home *** CD-ROM | disk | FTP | other *** search
/ Retro Gamer 17 / Retro Gamer 17.iso / 2D Shooters / install_hor.exe / runonce.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-12-06  |  5.5 KB  |  152 lines

  1. struct runonce {
  2.     int x, y, curframe, h, w, frames, dir;
  3.     int speed, animdelay, sprite, loop, toloop;
  4.     Uint32 lastmove, lastdrawn;
  5.     };
  6.     
  7. void initRunOnce (runonce *run, int h, int w, int frames,
  8.     int speed, int animdelay, int sprite) {
  9.     run->x=0; run->y=0; run->curframe=0; run->h= h; run->w= w;
  10.     run->frames= frames; run->dir= NOMOVEMENT; run->speed=speed;
  11.     run->animdelay= animdelay; run->sprite= sprite;
  12.     run->lastmove=0; run->lastdrawn=0;
  13.     }
  14.  
  15. void initRunOnce (runonce *run, int h, int w, int frames,
  16.     int speed, int animdelay, int sprite, int toloop) {
  17.     run->x=0; run->y=0; run->curframe=0; run->h= h; run->w= w;
  18.     run->frames= frames; run->dir= NOMOVEMENT; run->speed=speed;
  19.     run->animdelay= animdelay; run->sprite= sprite;
  20.     run->toloop= toloop; run->loop=0;
  21.     run->lastmove=0; run->lastdrawn=0;
  22.     }
  23.     
  24. void moveclips (runonce *run) {
  25.     for (int j=0; j < 32; j++) {
  26.         if ( run[j].sprite != NOSPRITE ) {
  27.                 if (run[j].dir == DOWN) {
  28.                      run[j].y+=run[j].speed;
  29.                      }
  30.                 if (run[j].dir == UP) {
  31.                      run[j].y-=run[j].speed;
  32.                      }                     
  33.                 if (run[j].dir == LEFT) {
  34.                      run[j].x-=run[j].speed;
  35.                      }        
  36.                 if (run[j].dir == RIGHT) {
  37.                      run[j].x+=run[j].speed;
  38.                      }
  39.                 if (run[j].dir == UPRIGHT) {
  40.                      run[j].x+=run[j].speed;
  41.                      run[j].y-=run[j].speed;
  42.                      }
  43.                 if (run[j].dir == DOWNRIGHT) {
  44.                      run[j].x+=run[j].speed;
  45.                      run[j].y+=run[j].speed;
  46.                      }
  47.                 if (run[j].dir == DOWNLEFT) {
  48.                      run[j].x-=run[j].speed;
  49.                      run[j].y+=run[j].speed;
  50.                      }        
  51.                 if (run[j].dir == UPLEFT) {
  52.                      run[j].x-=run[j].speed;
  53.                      run[j].y-=run[j].speed;
  54.                      }                             
  55.  
  56.                 if (run[j].sprite == ABSORB) {
  57.                      run[j].x=pc.x; run[j].y=pc.y;
  58.                      }                                                       
  59.                 if (run[j].y > 800) run[j].sprite= NOSPRITE;
  60.                 if (run[j].x > 1000) run[j].sprite= NOSPRITE;
  61.                 if (run[j].y < -200-run[j].h) run[j].sprite= NOSPRITE;
  62.                 if (run[j].x < -200-run[j].w) run[j].sprite= NOSPRITE;
  63.                 }
  64.             
  65.         }
  66.     }
  67.  
  68.  
  69. void drawclips (runonce *cur, SDL_Surface *app) {
  70.     for (int j=0; j < 32; j++) {
  71.         if ( cur[j].sprite != NOSPRITE ) {
  72.             SDL_Rect dest;
  73.             dest.x= cur[j].x; dest.y= cur[j].y;
  74.             dest.w= cur[j].w; dest.h= cur[j].h;
  75.             SDL_Rect src;
  76.             src.x= 0; src.y= 0;
  77.             src.w= cur[j].w; src.h= cur[j].h;
  78.  
  79.             if (cur[j].sprite == EXPLODE16) {
  80.                 SDL_BlitSurface(cast.explosion16[cur[j].curframe], &src, app, &dest);
  81.                 }
  82.             if (cur[j].sprite == EXPLODE64) {
  83.                 SDL_BlitSurface(cast.explosion64[cur[j].curframe], &src, app, &dest);
  84.                 }
  85.             if (cur[j].sprite == SHIELDSLOW) {
  86.                 SDL_BlitSurface(cast.shieldslow[cur[j].curframe], &src, app, &dest);
  87.                 }
  88.             if (cur[j].sprite == GAMEOVER) {
  89.                 SDL_BlitSurface(cast.gameover[cur[j].curframe], &src, app, &dest);
  90.                 }
  91.             if (cur[j].sprite == SPEEDUP) {
  92.                 SDL_BlitSurface(cast.speedup[cur[j].curframe], &src, app, &dest);
  93.                 }                
  94.             if (cur[j].sprite == ABSORB) {
  95.                 SDL_BlitSurface(cast.absorb[cur[j].curframe], &src, app, &dest);
  96.                 }          
  97.             if (cur[j].sprite == CLOUD) {
  98.                 SDL_BlitSurface(cast.cloud[cur[j].curframe], &src, app, &dest);
  99.                 }       
  100.             if (cur[j].sprite == EARTH) {
  101.                 SDL_BlitSurface(cast.earth[cur[j].curframe], &src, app, &dest);
  102.                 }     
  103.             if (cur[j].sprite == SUN) {
  104.                 SDL_BlitSurface(cast.sun[cur[j].curframe], &src, app, &dest);
  105.                 }     
  106.  
  107.             if( SDL_GetTicks() - cur[j].lastdrawn > cur[j].animdelay) {
  108.                 cur[j].curframe++;
  109.                 cur[j].lastdrawn= SDL_GetTicks();
  110.                 }
  111.             if( cur[j].curframe == cur[j].frames ) { 
  112.                         cur[j].curframe=0;
  113.                         if (cur[j].loop <= cur[j].toloop) cur[j].loop++; 
  114.                         if (cur[j].loop > cur[j].toloop) {
  115.                             cur[j].loop=0; 
  116.                             cur[j].sprite= NOSPRITE;
  117.                             }
  118.                         }
  119.             }
  120.         }
  121.     }          
  122.  
  123.  
  124. void dropclip (runonce sprite, runonce *cur, int ai,
  125.                                          int sx, int sy) {
  126.     for (int j= 0; j < 32; j++) {
  127.         if ( cur[j].sprite == NOSPRITE ) {
  128.             cur[j]= sprite;
  129.             cur[j].y= sy; cur[j].x= sx;
  130.             cur[j].dir= ai;
  131.             
  132.                       
  133.             return;
  134.             }
  135.         }
  136.     }
  137.  
  138.  
  139. runonce explosion16;
  140. runonce explosion64;
  141. runonce shieldsarelow;
  142. runonce gameover;
  143. runonce speedup;
  144. runonce absorb;
  145. runonce cloud;
  146. runonce fastcloud;
  147. runonce sun;
  148. runonce earth;
  149. runonce clips[32];
  150. runonce bottomclips[32];
  151.     
  152.